﻿<include file='Public:header' />
<script type="text/javascript" src="/Public/js/ajaxFileUpload.js"></script>
<style>
    .picture
    {
        display: inline-block;
        width: 300px;
    }
    .picture li
    {
        list-style-type: none;
        width: 350px;
    }
</style>
<div class="wrapper">
    <div class="main">
        <div class="left">
            <br />
            <div class="piclist">
                <div class="left">
                    <input id='uid' type='hidden' value='{$uid}' />
		    		<input type="button" value="{$Think.lang.goback}" onclick="goback('/Users/userProfile/uid/{$uid}');"/>
					<input type="file" id="aFile" name="aFile" /><input id="btnUpload" type="button" value="upload"/>
					
			
                </div>
                <div style="clear: both">
                </div>
                <br />
                <ul id='J_imageView' class='picture'>
                    
                    <li>
                     
                    </li>
                </ul>
                <div style="clear: both">
                </div>

            </div>
        </div>
        <div style="clear: both">
        </div>
    </div>
</div>
<script>
    $(function(){
    	loadPicture(1);
    
    	$('#btnUpload').click(function(){
    		uploadImg();
    	});
    });
    

    function uploadImg() {
		var thumbPrefix = 'avatar_w200_w200_';
		var uid = $('#uid').val();
		$.ajaxFileUpload({
            url: '/Public/mobileUploadImg',
            secureuri: false,
            fileElementId: 'aFile',
            data:{prefix:thumbPrefix,thumbW:200,thumbH:200,uid:uid},
            type:'json',
            success: function(data){
            	var obj = $.parseJSON(data);
            	if (obj.status == 1) {
            		loadPicture(1);
            	} else {
            		alert(obj.msg);	
            	}
            },
            error: function () {
                alert("{$Think.lang.upload_failed}");
            }
        });
	}

    function loadPicture(deletable) {
        var uid = $('#uid').val();
        $.post('/Users/loadPicture', { uid: uid }, function (data) {
            var obj = $.parseJSON(data);
            if (obj.status == 0) {
                alert('{$Think.lang.load_data_failed}');
                return false;
            }
         
            var div = $('#J_imageView');
            div.html('');
            var imgs = obj.data;
            if (imgs != null) {
                for (i = 0; i < imgs.length; i++) {
                    if (deletable == '1') {
                    	div.append('<li> <div style="width:195px"> <div class="piclistdiv"><img style="width:179px" src="' + imgs[i].name + '" ' + 'onload="imgReSize(this,179,179)"  /></a>' +
                    	"<a class='del-btn fr' href='javascript:void(0);' title='删除这张图片' onclick='delPic(" + imgs[i].id + ")'> x</a></div></div></li>");
                    } 
                }
            }
        });
    }
    
    
    function insertPicture(imgNames) {
        var uid = $('#uid').val();

        $.post('/Users/insertPicture', { uid: uid, imgNames: imgNames }, function (data) {
            var obj = $.parseJSON(data);
            var result = obj.status;

            if (result == 0) {
                alert('{$Think.lang.pls_enter_basic_info}');
            } else if (result == 1) {
                alert('{$Think.lang.pls_upload_img}');
            } else if (result == 2) {
                //alert('{$Think.lang.add_success}');
                $('#J_imageView').html('');
                loadPicture(1);
            } else if (result == 3) {
                alert('{$Think.lang.add_failed}');
            }
        });
    }



    function delPic(pid) {
        $.post('/Users/delPic', { pid: pid }, function (data) {
            var obj = $.parseJSON(data);
            if (obj.status == 1) {
                clearDiv();
                loadPicture(1);
            } else {
                alert(obj.msg);
            }
        });
    }
    function clearDiv() {
        $('#J_imageView').html('');
    }
</script>
<include file='Public:footer' />
